from typing import Union

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

import data

app = FastAPI()
# 配置允许域名
origins = [
    "http://localhost:5173",
]
# 配置允许域名列表、允许方法、请求头、cookie等
app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)


@app.get("/items/{item_id}")
async def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}


@app.post("/analysis")
async def analysis(index: int):
    return data.fixList[index]


@app.get("/history")
async def history():
    return data.history
